package client;


import java.util.*;
import java.io.*;
import java.net.*;
import javax.swing.JFrame;
import javax.swing.JOptionPane;


public class Client {
    private static UsersList ul;
    private static Properties applicationProps;
    private static final String PROPS_FILE = "properties";
    private static String login;
    private static String hash;
    private static byte status;
    
    public static void main(String[] args){
        
        
        applicationProps = loadProperties();
        System.out.println("wczytuje properties");
        if(applicationProps == null) {
            JOptionPane.showMessageDialog(new JFrame(), "Zarejestruj nowe konto.", "Uzytkownik niezarejestrowany", JOptionPane.INFORMATION_MESSAGE);
            applicationProps = new Properties();
            new Registration();
        }
        else {
            login = applicationProps.getProperty("login");
            hash = applicationProps.getProperty("hash");
            ul = new UsersList();
        }
        
        
    
    }
    
    public static Properties loadProperties() {
        FileInputStream in = null;
        Properties props = new Properties();
        try {
            in = new FileInputStream(PROPS_FILE);
            props.load(in);
            in.close();

        } catch (FileNotFoundException ex) {
            System.err.println("Nie znaleziono pliku Properties");
            return null;
        } catch (IOException ex) {
            System.err.println("Blad przy otwieraniu Properties");
        }
        
        return props;
    }
     
    public static void saveProperties(String login, String hash) {
        try {
            FileOutputStream out = new FileOutputStream(PROPS_FILE);
            applicationProps.setProperty("login", login);
            applicationProps.setProperty("hash", hash);
            applicationProps.store(out, "---No Comment---");
            out.close();
        } catch (IOException e) {
            System.err.println("Blad przy zapisywaniu Properties");
            e.printStackTrace();
        }
    }
    
    public static String getLogin() { return login; }
    public static void setLogin(String l) { login = l; }
    public static String getHash() { return hash; }
    public static void setHash(String h) { hash = h; }
    public static byte getStatus() { return status; }
    public static void setStatus(byte s) { status = s; }
    
    public static Properties getProperies() { return applicationProps; }
    
    
}


